package cn.infomany.functions;

import cn.infomany.util.IdWorker;
import org.beetl.core.Context;
import org.beetl.core.Function;

public class SnowFlakeFunction implements Function {

    public Long call(Object[] params, Context ctx) {

        IdWorker worker;
        if (params.length == 0) {
            worker = new IdWorker(1, 1, 1);
        } else if (params.length == 3) {
            worker = new IdWorker((Long) params[0], (Long) params[1], (Long) params[2]);
        } else if (params.length == 2) {
            worker = new IdWorker((Long) params[0], (Long) params[1], 1);
        } else if (params.length == 1) {
            worker = new IdWorker((Long) params[0], 1, 1);
        } else {
            worker = new IdWorker((Long) params[0], (Long) params[1], (Long) params[2]);
        }

        return worker.nextId();
    }

}